package com.supplychainapi.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 拦截器配置中心
 * @author xiezhiwei
 *
 */
@Configuration
public class MyCustomWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
	
	private Logger logger = LoggerFactory.getLogger(MyCustomWebMvcConfigurerAdapter.class);

    @Autowired
    private PhoneSignIntercepter phoneSignIntercepter;

	@Autowired
    private PhoneAuthIntercepter phoneAuthIntercepter;



    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	logger.info("-----需要拦截的控制器配置中心-----");
    	String[] phonePath = new String[]{
    	        "/phone/**", // 手机端请求拦截
    	};


        super.addInterceptors(registry);


        /* 手机端请求先针对签名进行验证 */
        registry.addInterceptor(phoneSignIntercepter)
                .addPathPatterns("/phone/**");

        /* 手机端请求先针对登录和权限验证 */
        registry.addInterceptor(phoneAuthIntercepter)
                .addPathPatterns("/phone/**")
                .excludePathPatterns("/phone/v*/user/login");
    }
}
